
package com.wzy.floatactionbutton2;

import android.util.Log;
import android.view.MotionEvent;

/**
 * FloatingActionButton的move监听器
 * 
 * @author wangzhenyu
 *
 */
class DirectionMoveListener implements ViewMoveListener {
    private static final String TAG = "DirectionScrollListener";
    private static final int DISTANCE_CHANGE_THRESHOLD = 1; // 移动距离最小值
    private final FloatingActionButton mFloatingActionButton;
    private float mPreY = -1;
//    private Handler mHandler;
    
    DirectionMoveListener(FloatingActionButton floatingActionButton) {
        mFloatingActionButton = floatingActionButton;
//        mHandler = new Handler();
    }
    
    @Override
    public void onMoving(MotionEvent event) {
        
        boolean goingDown = false;
        boolean changed = true;
        
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mPreY = event.getY();
            break;
        case MotionEvent.ACTION_MOVE:
            float curY = event.getY();
            float deltaY = curY - mPreY;
            Log.d(TAG, "deltaY:" + deltaY);
            changed = Math.abs(deltaY) > DISTANCE_CHANGE_THRESHOLD;
            goingDown = deltaY < 0;
            if (changed) {
                mFloatingActionButton.hide(goingDown);
            }
            mPreY = curY;
            break;
        case MotionEvent.ACTION_UP:
//            Runnable runnable = new Runnable() {
//                @Override
//                public void run() {
//                    mFloatingActionButton.hide(false);
//                }
//            };
//            mHandler.removeCallbacks(runnable);
//            mHandler.postDelayed(runnable, 1000);
            break;
        default:
            break;
        }
        
    }
    
}